/*
 * 文件名：OrderInfoService.java
 * 版权：Copyright by www.huawei.com
 * 描述：
 * 修改人：zhangshaohua
 * 修改时间：2016年4月25日
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */

package com.zcsy.manage.distribution.service.mall.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zcsy.manage.distribution.common.StringUtil;
import com.zcsy.manage.distribution.service.mall.CIOrderInfoService;
import com.zcsy.manage.model.dmall.vo.OrderDetailVo;
import com.zcsy.manage.model.dmall.vo.OrderInfoVo;
import com.zcsy.manage.model.mall.OrderInfo;
import com.zcsy.manage.persistence.dmall.DisOrderInfoDao;
import com.zcsy.manage.persistence.mall.OrderInfoDao;
import com.zcsy.manage.persistence.system.RoleCellDao;
import com.zcsy.manage.persistence.system.UserDao;

/**
 * 
 * @Title: OrderInfoService.java @Package： com.zcsy.manage.service.mall.impl
 * @Description: 订单服务实现类
 * @author zhangsh zsh3384027@gmail.com
 * @Copyright: 2016 武汉恒数利通技术有限公司 All rights reserved.
 * @date 2016年4月25日
 * @version 1.0
 * @see JDK1.8.0_45
 * @since
 */
@Service
public class COrderInfoServiceImpl implements CIOrderInfoService {

	@Autowired
	private OrderInfoDao orderInfoDao;

	@Autowired
	private DisOrderInfoDao disOrderInfoDao;
	
	@Autowired
	private RoleCellDao roleCellDao;
	
	@Autowired
	private UserDao userDao;

	public List<OrderInfo> selectByKeyword(OrderInfo orderInf) {
		return orderInfoDao.selectByKeyword(orderInf);
	}

	public List<OrderInfo> selectOrder(Map<String, Object> orderInfo) {
		return orderInfoDao.selectOrder(orderInfo);
	}

	@Override
	public SXSSFWorkbook createOrderExcel(Map<String, Object> orderInfo) {
		List<OrderInfo> list = orderInfoDao.selectOrder(orderInfo);

		// 创建一个新的Excel
		SXSSFWorkbook workBook = new SXSSFWorkbook();
		// 创建sheet页
		Sheet sheet = workBook.createSheet();

		// sheet页名称
		workBook.setSheetName(0, "汇总表");

		// 设置第一行为Header
		Row firHeadRow = sheet.createRow(0);

		// 单元格样式
		CellStyle cellStyle = workBook.createCellStyle();
		cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中
		Font font = workBook.createFont();
		font.setFontName("黑体");
		font.setFontHeightInPoints((short) 14);// 设置字体大小
		cellStyle.setFont(font);// 选择需要用到的字体格式

		// 设置第二行Herder
		String secHead = "订单号,商品总价,优惠券ID,优惠券抵扣金额,运费,最终价格,花费积分,创建时间,配送送达时间,确认收货时间";
		String[] secHeads = secHead.split(",");

		// 生成一行标题并合并单元格
		for (int i = 0; i < secHeads.length; i++) {
			firHeadRow.createCell(i);
		}
		
		sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, secHeads.length - 1));
		firHeadRow.getCell(0).setCellValue("订单报表");
		firHeadRow.getCell(0).setCellStyle(cellStyle);

		Row secHeadRow = sheet.createRow(1);
		for (int i = 0; i < secHeads.length; i++) {
			secHeadRow.createCell(i).setCellValue(secHeads[i]);
		}

		// 填充表格
		if (list.size() > 0) {

			for (OrderInfo item : list) {
				Row row = sheet.createRow(sheet.getLastRowNum() + 1);
				row.createCell(0).setCellValue(StringUtil.objectToString(item.getOrderNumber()));
				row.createCell(1).setCellValue(StringUtil.objectToString(item.getTotalPrice()));
				row.createCell(2).setCellValue(StringUtil.objectToString(item.getCouponId()));
				row.createCell(3).setCellValue(StringUtil.objectToString(item.getCouponPrice()));
				row.createCell(4).setCellValue(StringUtil.objectToString(item.getCarriage()));
				row.createCell(5).setCellValue(StringUtil.objectToString(item.getFinalPrice()));
				row.createCell(6).setCellValue(StringUtil.objectToString(item.getCostIntegral()));
				row.createCell(7).setCellValue(StringUtil.objectToString(item.getCreateTime()));
				row.createCell(8).setCellValue(StringUtil.objectToString(item.getArriveTime()));
				row.createCell(9).setCellValue(StringUtil.objectToString(item.getConfirmTime()));
			}
			
		}

		return workBook;
	}

	public OrderInfo selectByOrderNumber(String ordernumber) {
		return orderInfoDao.selectByOrderNumber(ordernumber);
	}

	public int updateState(OrderInfo oInfo) {
		return orderInfoDao.updateState(oInfo);
	}

	public List<Map<String, Object>> selectOrderSender(Map<String, Object> map) {
		return orderInfoDao.selectOrderSender(map);
	}

	@Override
	public int assignOrder(OrderInfo orderInfo) {
		return orderInfoDao.assignOrder(orderInfo);
	}

	@Override
	public List<Map<String, Object>> selectByDate(Map<String, Object> map) {
		return orderInfoDao.selectByDate(map);
	}

	@Override
	public List<Map<String, Object>> selectOrderInfo(Map<String, Object> map) {
		return orderInfoDao.selectOrderInfo(map);
	}

	@Override
	public List<OrderDetailVo> selectOrderDetailInfo(String ordernumber) {
		return disOrderInfoDao.selectOrderDetailInfo(ordernumber);
	}

	@Override
	public int selectToday(List<String> list) {
		return orderInfoDao.selectToday(list);
	}

	@Override
	public int selectPeiSong(String loginname) {
		return orderInfoDao.selectPeiSong(loginname);
	}

	@Override
	public int selectMonth(List<String> list) {
		return orderInfoDao.selectMonth(list);
	}

	@Override
	public int selectWeek(String loginname,String startTime,String endTime) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("loginname", loginname);
		map.put("startTime", startTime);
		map.put("endTime", endTime);
		return orderInfoDao.selectWeek(map);
	}

	@Override
	public List<Map<String, Object>> selectOrder1(Map<String, Object> map) {
		return orderInfoDao.selectOrder1(map);
	}

	@Override
	public List<Map<String, Object>> selectOrder0(Map<String, Object> map) {
		return orderInfoDao.selectOrder0(map);
	}

	@Override
	public List<Map<String, Object>> selectOrder2(Map<String, Object> map) {
		return orderInfoDao.selectOrder2(map);
	}

	@Override
	public List<Map<String, Object>> selectByDate1(Map<String, Object> map) {
		return orderInfoDao.selectByDate1(map);
	}

	@Override
	public List<Map<String, Object>> selectOrderSender1(Map<String, Object> map) {
		return orderInfoDao.selectOrderSender1(map);
	}

	@Override
	public List<OrderInfoVo> selectByStateAndSenderAccount(Map<String, Object> params) {
		return disOrderInfoDao.selectByStateAndSenderAccount(params);
	}

	@Override
	public List<OrderInfoVo> selectAllOrderListForDistribution(Map<String, Object> params) {
		return disOrderInfoDao.selectAllOrderListForDistribution(params);
	}
	
	@Override
	public List<OrderInfoVo> selectAllWaitForDealOrderListForDistribution(Map<String, Object> params) {
		return disOrderInfoDao.selectAllWaitForDealOrderListForDistribution(params);
	}
	
	@Override
	public int selectCounts(Map<String, Object> params) {
		return disOrderInfoDao.selectCounts(params);
	}

}
